package com.dfiov.cloud.msmtools.mapper.msuser;

import com.dfiov.cloud.msmtools.mapper.entity.msuser.BaseLoginAccountAuthDo;
import com.dfiov.cloud.msmtools.mapper.entity.msuser.BaseUserAtributesDo;
import com.dfiov.cloud.msmtools.mapper.entity.msuser.BaseUserInfoDo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MsUserMapper {

    @Select("<script> " +
            "SELECT A.user_account_sid as userAccountSid, A.login_id as loginId, A.login_type as loginType " +
            "FROM base_login_account_auth A " +
            "WHERE A.del_flag = 0 " +
            "<if test='phone!=null'> AND A.login_id = #{phone} </if> " +
            "</script>")
    List<BaseLoginAccountAuthDo> getLoginAccountAuth(@Param("phone")String phone);

    @Select("<script> " +
            "SELECT sid " +
            "FROM base_user_profile A " +
            "WHERE A.del_flag = 0 " +
            "<if test='phone!=null'> AND A.mobile_phone = #{phone} </if> " +
            "<if test='userAccountSid!=null'> AND A.user_account_sid = #{userAccountSid} </if> " +
            "</script>")
    List<Long> getProfileSid(@Param("phone")String phone, @Param("userAccountSid")Long userAccountSid);

    @Select("<script> " +
            "SELECT mobile_phone " +
            "FROM base_user_profile A " +
            "WHERE A.del_flag = 0 " +
            "<if test='userAccountSid!=null'> AND A.user_account_sid = #{userAccountSid} </if> " +
            "</script>")
    List<String> getProfileMobile(@Param("userAccountSid")Long userAccountSid);

    @Select("<script> " +
            "SELECT account_id " +
            "FROM base_user_account A " +
            "WHERE A.del_flag = 0 " +
            "<if test='userAccountSid!=null'> AND A.sid = #{userAccountSid} </if> " +
            "</script>")
    List<String> getAccountId(@Param("userAccountSid")Long userAccountSid);

    @Select("<script> " +
            "SELECT count(*) " +
            "FROM base_user_account A " +
            "WHERE A.del_flag = 0 " +
            "<if test='accountId!=null'> AND A.account_id = #{accountId} </if> " +
            "</script>")
    int findbyAccountId(@Param("accountId")String accountId);

    @Select("<script> " +
            "SELECT A.attribute_code as attributeCode, A.attribute_value as attributeValue " +
            "FROM base_user_atributes A " +
            "WHERE A.del_flag = 0 and A.attribute_code in ('lechebangUid','namiUid','lianyouUid','tencentUserId','dpcaUid','megatronixUid','pateoEcologyUid') " +
            "<if test='sid!=null'> AND A.user_sid = #{sid} </if> " +
            "</script>")
    List<BaseUserAtributesDo> getUserAtributes(@Param("sid")Long sid);

    @Select("<script> " +
            "SELECT count(*) " +
            "FROM base_user_atributes A " +
            "WHERE A.del_flag = 0 " +
            "<if test='AttributeCode!=null'> AND A.attribute_code = #{AttributeCode} </if> " +
            "<if test='AttributeValue!=null'> AND A.attribute_value = #{AttributeValue} </if> " +
            "</script>")
    int findbyAttributeValue(@Param("AttributeCode")String AttributeCode, @Param("AttributeValue")String AttributeValue);

    BaseUserInfoDo getUserInfoByAccountId(@Param("accountId") String accountId);

    BaseUserInfoDo getUserInfoByAccountSid(@Param("userAccountSid") Long userAccountSid);
}
